package com.mall.system.convert;

import com.mall.common.entity.gateway.GatewayLog;
import com.mall.system.entity.SysLog;

/**
 * 网关日志转换器
 */
public class GatewayLogConverter {
    
    /**
     * 将网关日志转换为系统日志
     * 
     * @param gatewayLog 网关日志
     * @return 系统日志
     */
    public static SysLog convertToSysLog(GatewayLog gatewayLog) {
        if (gatewayLog == null) {
            return null;
        }
        
        SysLog sysLog = new SysLog();
        sysLog.setId(gatewayLog.getId());
        sysLog.setTraceId(gatewayLog.getTraceId());
        sysLog.setUserId(gatewayLog.getUserId());
        sysLog.setOperation("网关请求: " + gatewayLog.getMethod() + " " + gatewayLog.getUri());
        sysLog.setMethod(gatewayLog.getMethod() + ":" + gatewayLog.getUri());
        sysLog.setParams(gatewayLog.getParams());
        sysLog.setResponse(gatewayLog.getResponseData());
        sysLog.setTime(gatewayLog.getTime());
        sysLog.setIp(gatewayLog.getIp());
        sysLog.setCreateTime(gatewayLog.getRequestTime());
        
        return sysLog;
    }
}